#![cfg_attr(feature = "axstd", no_std)]
#![cfg_attr(feature = "axstd", no_main)]

extern crate axplat_aarch64_phytium_pi;

#[cfg(feature = "axstd")]
use axstd::println;

use axhal::uart;

#[cfg_attr(feature = "axstd", unsafe(no_mangle))]
fn main() {
    println!("println: this is uart cem5826m11 demo.");

    let mut uart_system = uart::UartSystem::new();
    let uart = uart_system.controller(1).unwrap();

    uart.init_no_irq(100_000_000, 115200);
    let send_data = "get_all";
    uart.put_line_poll(send_data);
    println!("send data {send_data}");

    loop {
        let mut read_buf = [0; 1024];
        let read_len = uart.read_line_poll(&mut read_buf);

        let read_data = unsafe { core::str::from_utf8_unchecked(&read_buf[..read_len]) };
        println!("read data {read_data}");
    }
}
